from scavenger import Scavenger
from time import sleep, time

sleep(1.2)

peers = Scavenger.get_peers()
for peer in peers:
    print peer
if len(peers) != 0:
    print 'start'
    start = time()
    print Scavenger.perform_service(peers[0], 'daimi.test.add', {'x':1, 'y':1}, timeout=2)
    print 'done - elapsed =', time()-start
    
    print 'installing service'
    start = time()
    if not Scavenger.has_service(peers[0], 'daimi.test.subtract'):
        Scavenger.install_service(peers[0], 'daimi.test.subtract',"""
def perform(x, y):
    z = 0
    for v in range(0,100000):
        z += v
    return x - y
""")
    print 'done - elapsed =', time()-start
    
    print 'start'
    start = time()
    print Scavenger.perform_service(peers[0], 'daimi.test.subtract', {'x':1, 'y':1}, timeout=2)
    print 'done - elapsed =', time()-start
    
Scavenger.shutdown()
